home *** CD-ROM | disk | FTP | other *** search
Text File | 2003-07-17 | 83.7 KB | 3,155 lines |
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // $Source: /vobs/aw/Maya/src/Maya/Maya/scripts/hotkeyEditor.mel $
- //
- // $Locker: $
- //
- // $Author: kpicott $
- // $Revision: /main/62 $
- // $Date: 2000/05/16 12:30:32 $
- //
- // Description:
- // This contains procedures necessary for
- // the Hotkey/NameCommand editor.
- //
-
- /*
- //
- // These are the local and global procedures defined in this file. As well
- // as the unique names of the UI objects created.
- //
- // ----------------------------------------------------------------------
- //
-
- // Local procedures.
- //
- string constructHotkeyCommand(string $key, int $ctrl,
- int $alt, int $press, string $command)
-
- int isValidKey(string $name)
- int isValidName(string $name)
- int isUniqueName(string $name)
- int isValidCategory(string $name)
- int isExistingCategory(string $name)
- string getCurrentCategory()
- string getCurrentRunTimeCommand()
- int getNameCommand(string $nameCommand)
- string [] getAllHotkeys(string $command)
-
- updateCommandInfo()
- updateCommandButtons()
- updateRemoveHotkeyButton()
- updateCurrentHotkeys()
- enableNewHotkeyArea(int $enable);
- setQueryHotkeyText(string $label)
- int updateQueryHotkeyText()
- updateCommandTextScrollList(string $command)
- updateCategoryPopupMenu()
- updateKeyPopupMenu()
-
- removeHotkey(string $hotkey)
- deleteRunTimeCommand(string $command)
-
- createCommandListArea()
- createCommandInfoArea()
- createCurrentHotkeyArea()
- createNewHotkeyArea()
- createButtonsArea()
-
- resetCreateOrEditMode()
-
- // Global procedures.
- //
- string[] getAllValidKeys()
- string getHotkeyCommand(string $key, int $ctrl,
- int $alt, int $press)
- string getRunTimeCommandFromNameCommand(string $nameCommand)
-
- hotkeyEditorCategoryTextScrollListSelect()
- hotkeyEditorCommandTextScrollListSelect()
-
- hotkeyEditorHotkeyKeyFieldChange()
- hotkeyEditorHotkeyCtrlCheckBoxChange()
- hotkeyEditorHotkeyAltCheckBoxChange()
- hotkeyEditorHotkeyPressRadioButtonChange()
- hotkeyEditorHotkeyReleaseRadioButtonChange()
- hotkeyEditorHotkeyTextScrollListSelect()
-
- hotkeyEditorCategoryPopupMenuSelect(string $category)
- hotkeyEditorKeyPopupMenuSelect(string $key)
-
- hotkeyEditorCreateCommand()
- hotkeyEditorEditCommand()
- hotkeyEditorDeleteCommand()
- hotkeyEditorAcceptCommand()
- hotkeyEditorCancelCommand()
- hotkeyEditorSearchForRunTimeCommand()
-
- hotkeyEditorAssignHotkey()
- hotkeyEditorQueryHotkey()
- hotkeyEditorFindHotkey()
- hotkeyEditorRemoveHotkey()
- hotkeyEditorRestoreDefaultHotkeys()
- hotkeyEditorListAllHotkeys()
-
- hotkeyEditorSave()
- hotkeyEditorClose()
-
- hotkeyEditor()
-
- // Interface for Marking Menu Editor - These procedures
- // should not be called from anywhere else.
- //
- string hotkeyEditor_generatePressAnnotationForMM(string)
- string hotkeyEditor_generateReleaseAnnotationForMM(string)
- int hotkeyEditor_createMarkingMenu(string, string, string)
- hotkeyEditor_deleteMarkingMenu(string)
- int hotkeyEditor_renameMarkingMenu(string, string, string, string)
- int hotkeyEditor_doesMarkingMenuExist(string)
-
- global int $gHotkeyEditorInCreateMode;
- global int $gHotkeyEditorInEditMode;
-
- // Names of UI objects.
- //
- HotkeyEditor
-
- HotkeyEditorCategoryTextScrollList
- HotkeyEditorCommandTextScrollList
-
- HotkeyEditorNameField
- HotkeyEditorDescriptionField
- HotkeyEditorCategoryField
- HotkeyEditorCategoryPopupMenuButton
- HotkeyEditorCategoryPopupMenu
- HotkeyEditorCommandField
-
- HotkeyEditorCreateCommandButton
- HotkeyEditorEditCommandButton
- HotkeyEditorDeleteCommandButton
- HotkeyEditorAcceptCommandButton
- HotkeyEditorCancelCommandButton
- HotkeyEditorSearchButton
-
- HotkeyEditorHotkeyTextScrollList
- HotkeyEditorRemoveHotkeyButton
- HotkeyEditorRestoreDefaultHotkeysButton
- HotkeyEditorListAllHotkeysButton
-
- HotkeyEditorKeyLabel
- HotkeyEditorKeyField
- HotkeyEditorKeyPopupMenuButton
- HotkeyEditorKeyPopupMenu
- HotkeyEditorModifierLabel
- HotkeyEditorCtrlCheckBox
- HotkeyEditorAltCheckBox
- HotkeyEditorDirectionLabel
- HotkeyEditorPressRadioButton
- HotkeyEditorReleaseRadioButton
- HotkeyEditorRepeatableLabel
- HotkeyEditorRepeatableCheckBox
- HotkeyEditorAssignHotkeyButton
- HotkeyEditorQueryHotkeyButton
- HotkeyEditorFindHotkeyButton
- HotkeyEditorQueryResultText
-
- HotkeyEditorSaveButton
- HotkeyEditorCloseButton
- */
-
-
- proc string constructHotkeyCommand(
- string $key,
- int $ctrl,
- int $alt,
- int $cmd,
- int $press,
- int $repeat,
- string $command)
- //
- // Description:
- // Construct and return a string containing a valid hotkey command
- // that can be passed to the eval() funtion.
- //
- // Arguments:
- // key - The key string.
- // ctrl - True if Ctrl modifer is required, false otherwise.
- // alt - True if Alt modifer is required, false otherwise.
- // press - True for key press, false for key release.
- // repeat - True if the hotkey is repeatable, false otherwise.
- // command - The command string to execute.
- //
- {
- // Must surround the key string in double quote characters.
- //
- string $result = ("hotkey -k \"");
-
- // Must preceed back slashes and double quote characters with
- // a backslash.
- //
- if ("\\" == $key || "\"" == $key) $key = "\\" + $key;
-
- $result += ($key + "\" ");
-
- if ($ctrl) $result += "-ctl ";
- if ($alt) $result += "-alt ";
- if ($cmd) $result += "-cmd";
-
- if ($press) $result += "-name \"";
- else $result += "-releaseName \"";
-
- $result += ($command + "\" ");
-
- if ($press) $result += "-pressCommandRepeat ";
- else $result += "-releaseCommandRepeat ";
-
- $result += $repeat;
-
- return $result;
- }
-
- proc int isValidKey(string $name)
- //
- // Description:
- // Return true if the given string corresponds to a valid key
- // that a hotkey can be assigned to.
- //
- // See the getAllValidKeys() procedure for a list of all the
- // valid keys. For example, "a", "Page_Down", and "\\" are all
- // valid keys. However, "Foo", " ", and "f1" (must be uppercase)
- // are not.
- //
- {
- int $result = false;
- string $keys[] = getAllValidKeys();
-
- for ($key in $keys) {
- if ($name == $key) {
- $result = true;
- break;
- }
- }
-
- return $result;
- }
-
- proc int isValidName(string $name)
- //
- // Description:
- // Determine if the given string is potentially a valid name.
- // Note that this procedure does not test to see if the name is
- // unique, it just tests the string characters.
- //
- // Check to ensure that the string does not begin with a number
- // and is followed only by alphanumeric characters or underscores.
- //
- {
- int $result = false;
-
- if ("" != $name) {
- //
- // Begins with letter or underscore, followed by
- // letters, digits, or underscores.
- //
- string $regExpr = "([a-zA-Z_]+)([[a-zA-Z0-9_])*";
- string $temp = match($regExpr, $name);
- if ($temp == $name) {
- $result = true;
- }
- }
-
- return $result;
- }
-
- proc int isUniqueName(string $name)
- //
- // Description:
- // Determine if the given string is a unique name.
- //
- // Compare it with existing commands, scripts, and procedures.
- //
- {
- int $result = false;
-
- if ("Unknown" == `whatIs $name`) {
- $result = true;
- }
-
- return $result;
- }
-
- proc int isValidCategory(string $category)
- //
- // Description:
- // Determine if the given string is potentially a valid category.
- //
- // Check to ensure that the string does not begin with a number
- // and is followed only by alphanumeric characters, underscores,
- // or spaces.
- //
- {
- int $result = false;
-
- if ("" != $category) {
- //
- // Begins with letter or underscore, followed by
- // letters, digits, spaces, or underscores.
- //
- string $regExpr = "([a-zA-Z_]+)([[a-zA-Z0-9_ ])*";
- string $temp = match($regExpr, $category);
- if ($temp == $category) {
- $result = true;
- }
- }
-
- return $result;
- }
-
- proc int isExistingCategory(string $name)
- //
- // Description:
- // Determine if the given category already exists.
- //
- {
- int $result = false;
-
- string $categories[] = `textScrollList -query -allItems
- HotkeyEditorCategoryTextScrollList`;
- int $index, $numberOfCategories = size($categories);
-
- for ($index = 0; $index < $numberOfCategories; $index++) {
- if ($name == $categories[$index]) {
- $result = true;
- break;
- }
- }
-
- return $result;
- }
-
- proc string getNameErrorMessage(string $name)
- //
- // Description:
- // Construct an appropriate error message for the given name.
- //
- // The error message will take into consideration whether
- // the name already refers to a command, script or procedure.
- //
- // An empty string is returned if the name is unique.
- //
- {
- string $result = "";
-
- string $whatIsResult = `whatIs $name`;
- string $buffer[];
- int $tokenCount = `tokenize $whatIsResult $buffer`;
-
- switch ($tokenCount) {
- case 1:
- if ("Unknown" == $buffer[0]) {
- $result = "";
-
- } else if ("Command" == $buffer[0]) {
- $result = "A command with the name " + $name
- + " already exists.\nPlease enter another name.";
- } else {
- $result = "The name " + $name
- + " is not unique.\nPlease enter another name.";
- }
- break;
-
- case 4:
- $result = "A script with the name " + $name
- + " already exists in\n" + $buffer[3]
- + ".\nPlease enter another name.";
- break;
-
- case 5:
- $result = "A MEL procedure with the name " + $name
- + " already exists in\n" + $buffer[4]
- + ".\nPlease enter another name.";
- break;
-
- default:
- $result = "The name " + $name
- + " is not unique.\nPlease enter another name.";
- break;
- }
-
- return $result;
- }
-
- proc string getCurrentCategory()
- //
- // Description:
- // Determine the current category of commands being displayed in the
- // Hotkey Editor.
- //
- {
- string $result = "", $category[];
-
- $category = `textScrollList -query -selectItem HotkeyEditorCategoryTextScrollList`;
-
- if (size($category) > 0 && "Uncategorized" != $category[0]) {
- $result = $category[0];
- }
-
- return $result;
- }
-
- proc string getCurrentRunTimeCommand()
- //
- // Description:
- // Determine the runTimeCommand currently selected by the user.
- //
- // Returns:
- // A string containing the name of the current selected
- // runTimeCommand. If no command is selected then an empty
- // string is returned.
- //
- {
- string $result = "", $command[];
-
- $command = `textScrollList -query -selectItem HotkeyEditorCommandTextScrollList`;
-
- if (size($command) > 0) {
- $result = $command[0];
- }
-
- return $result;
- }
-
- proc int getNameCommand(string $nameCommand)
- //
- // Description:
- // Determine if a nameCommand with the given name exists.
- //
- // Arguments:
- // nameCommand - The $nameCommand.
- //
- // Returns:
- // If the nameCommand exists then a 1 based index is returned.
- // This index can then be used for querying with the 'assignCommand'
- // command.
- //
- // If the nameCommand does not exist then 0 is returned.
- //
- {
- int $result = 0, $index;
- int $numberOfNameCommands = `assignCommand -query -numElements`;
-
- for ($index = 1; $index <= $numberOfNameCommands; $index++) {
- if ($nameCommand == `assignCommand -query -name $index`) {
- $result = $index;
- break;
- }
- }
-
- return $result;
- }
-
- proc string [] getAllHotkeys(string $command)
- //
- // Description:
- // Determine all the hotkeys that will invoke the specified
- // runTimeCommand.
- //
- // Returns:
- // A string array containing all the hotkeys attahed to the
- // specified command. Each string element in the array will
- // full describe the hotkey, for example: "Ctrl b", or "Alt Space",
- // or "N Release".
- //
- {
- string $result[], $keyInfo[], $hotkey, $cmd;
- int $resultIndex = 0, $index, $numberOfNameCommands;
- int $hotkeyInfoIndex, $numberOfHotkeys;
-
- if ("" != $command) {
- $numberOfNameCommands = `assignCommand -query -numElements`;
- for ($index = 1; $index <= $numberOfNameCommands; $index++) {
- $cmd = `assignCommand -query -command $index`;
- //
- // Is this nameCommand pointing to the target runTimeCommand?
- //
- if ($cmd == $command) {
- //
- // For this nameCommand determine all the hotkeys
- // that point to it.
- //
- $keyInfo = AWAppendStringsToStringArray(
- `assignCommand -query -keyArray $index`, $keyInfo);
-
- // Don't stop searching. There may be other nameCommand
- // objects that point to the specified runTimeCommand.
- }
- }
- }
-
- // The keyInfo array should now contain all the hotkeys that
- // point to the target runTimeCommand.
- //
- $hotkeyInfoIndex = 0;
- $numberOfHotkeys = size($keyInfo) / 5;
- for ($index = 0; $index < $numberOfHotkeys; $index++) {
- $hotkey = "";
- if ("1" == $keyInfo[$hotkeyInfoIndex + 2]) {
- if (`about -mac`) {
- $hotkey += ("control+");
- }
- else {
- $hotkey += ("Ctrl+");
- }
- }
- if ("1" == $keyInfo[$hotkeyInfoIndex + 1]) {
- if (`about -mac`) {
- $hotkey += ("option+");
- }
- else {
- $hotkey += ("Alt+");
- }
- }
-
- if ("1" == $keyInfo[$hotkeyInfoIndex + 4]) {
- $hotkey += ("command+");
- }
-
- if (" " == $keyInfo[$hotkeyInfoIndex]) {
- if (`about -mac`) {
- $hotkey += ("space");
- }
- else {
- $hotkey += ("Space");
- }
- } else {
- $hotkey += $keyInfo[$hotkeyInfoIndex];
- }
-
- if ("1" == $keyInfo[$hotkeyInfoIndex + 3]) {
- $hotkey += " Release";
- }
-
- // Command keys needs to be taken care of. So an extra field in the array. - Vidya.
-
- $hotkeyInfoIndex += 5;
-
- $result[$resultIndex++] = $hotkey;
- }
-
- return $result;
- }
-
- proc updateCommandInfo()
- //
- // Description:
- // Update the UI that displays information on the current
- // selected runTimeCommand.
- //
- // This procedure should be called whenever the current selected
- // runTimeCommand is changed.
- //
- {
- global int $gHotkeyEditorInCreateMode;
- global int $gHotkeyEditorInEditMode;
-
- string $name, $description, $command, $category, $focus;
- int $nameEditable = false, $descriptionEditable = false;
- int $commandEditable = false, $categoryEditable = false;
-
- // Get the current selected runTimeCommand and category.
- //
- $name = getCurrentRunTimeCommand();
- $category = getCurrentCategory();
-
- if ("" != $name) {
- //
- // Get the runTimeCommand's description and command.
- //
- $description = `runTimeCommand -query -annotation $name`;
- $command = `runTimeCommand -query -command $name`;
- }
-
- if ($gHotkeyEditorInCreateMode) {
- //
- // In Create mode, ie. the user pressed the "Create" button.
- //
- // In this mode clear out the name, description, and command
- // fields so the user can type in new values.
- //
- // Don't clear out the category field, it's most likely the
- // user will want to add the command to the current category.
- //
- $name = "";
- $description = "";
- $command = "";
-
- // Be sure to enable all the fields for editing.
- //
- $nameEditable = true;
- $descriptionEditable = true;
- $categoryEditable = true;
- $commandEditable = true;
-
- // Send keyboard focus to the name field.
- //
- $focus = "HotkeyEditorNameField";
-
- } else if ($gHotkeyEditorInEditMode) {
- //
- // In Edit mode, ie. the user pressed the "Edit" button.
- //
- // Don't clear out any of the fields, but do make them all
- // editable.
- //
- $nameEditable = true;
- $descriptionEditable = true;
- $categoryEditable = true;
- $commandEditable = true;
-
- // Send keyboard focus to the name field.
- //
- $focus = "HotkeyEditorNameField";
-
- } else {
- //
- // No mode.
- //
- }
-
- // Update the controls.
- //
- textField -edit -text $name -editable $nameEditable
- HotkeyEditorNameField;
- textField -edit -text $description -insertionPosition 1
- -editable $descriptionEditable
- HotkeyEditorDescriptionField;
- textField -edit -text $category
- -editable $categoryEditable
- HotkeyEditorCategoryField;
- iconTextButton -edit
- -enable $categoryEditable
- HotkeyEditorCategoryPopupMenuButton;
- scrollField -edit -text $command -insertionPosition 1
- -editable $commandEditable
- HotkeyEditorCommandField;
-
- if(`about -mac`){
- scrollField -edit -editable $commandEditable HotkeyEditorCommandField;
- }
-
-
-
- // Set keyboard focus.
- //
- if ("" != $focus) {
- setFocus $focus;
- }
- }
-
- proc updateCommandButtons()
- //
- // Description:
- // Update the command buttons.
- //
- // This procedure should be called whenever the current selected
- // runTimeCommand is changed, or when the mode of the command
- // area changes.
- //
- {
- global int $gHotkeyEditorInCreateMode;
- global int $gHotkeyEditorInEditMode;
-
- int $enableCreate = false, $enableEdit = false;
- int $enableDelete = false, $enableSearch = false;
- int $enableAccept = false, $enableCancel = false;
-
- string $key = `textField -query -text HotkeyEditorKeyField`;
- string $command = getCurrentRunTimeCommand();
- string $hotkeys[];
-
- // Should the Create Command button be enabled?
- //
- // It should always be enabled except for when the user presses
- // it or the Edit Command button. When that happens the button
- // should be disabled until the user presses either the
- // Accept or Cancel button.
- //
- if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode) {
- $enableCreate = true;
- }
-
- // Should the Edit Command button be enabled?
- //
- // It should be enabled if the selected command is not a default
- // one and if the user has not already pressed the Edit or Create
- // Command button.
- //
- if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode &&
- "" != $command && !`runTimeCommand -query -default $command`) {
- $enableEdit = true;
- }
-
- // Should the Delete command button be enabled?
- //
- // It should be enabled if the selected command is not a default
- // one and if the user has not already pressed the Edit or Create
- // Command button.
- //
- if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode &&
- "" != $command && !`runTimeCommand -query -default $command`) {
- $enableDelete = true;
- }
-
- // Should the Accept Command button be enabled?
- //
- // If the editor is in Create or Edit command mode then yes it should.
- //
- if ($gHotkeyEditorInCreateMode || $gHotkeyEditorInEditMode) {
- $enableAccept = true;
- }
-
- // Should the Cancel Command button be enabled?
- //
- // If the editor is in Create or Edit command mode then yes it should.
- //
- if ($gHotkeyEditorInCreateMode || $gHotkeyEditorInEditMode) {
- $enableCancel = true;
- }
-
- // Should the Search button be enabled?
- //
- // It should always be enabled except for when the user presses
- // it or the Edit Command button.
- //
- if (!$gHotkeyEditorInCreateMode && !$gHotkeyEditorInEditMode) {
- $enableSearch = true;
- }
-
- button -edit -enable $enableCreate HotkeyEditorCreateCommandButton;
- button -edit -enable $enableEdit HotkeyEditorEditCommandButton;
- button -edit -enable $enableDelete HotkeyEditorDeleteCommandButton;
- button -edit -enable $enableAccept HotkeyEditorAcceptCommandButton;
- button -edit -enable $enableCancel HotkeyEditorCancelCommandButton;
- button -edit -enable $enableSearch HotkeyEditorSearchButton;
- }
-
- proc updateRemoveHotkeyButton()
- //
- // Description:
- // Update the remove hotkey button.
- //
- // This procedure should be called whenever the current hotkey
- // selection changes.
- //
- {
- int $enableRemove = false;
-
- // Should the Remove Hotkey button be enabled?
- //
- // If there is a Hotkey selected in the Current Hotkeys list then
- // yes it should.
- //
- $hotkeys = `textScrollList -query -selectItem
- HotkeyEditorHotkeyTextScrollList`;
-
- if (size($hotkeys) > 0) {
- $enableRemove = true;
- }
-
- button -edit -enable $enableRemove HotkeyEditorRemoveHotkeyButton;
- }
-
- proc updateCurrentHotkeys()
- //
- // Description:
- // Update the area that informs the user what hotkeys are currently
- // assigned to the selected runTimeCommand.
- //
- {
- string $runTimeCommand = getCurrentRunTimeCommand();
- string $hotkey, $hotkeys[];
- textScrollList -edit -removeAll HotkeyEditorHotkeyTextScrollList;
-
- // Search through all nameCommands for the ones that point
- // to the runTimeCommand argument.
- //
- $hotkeys = getAllHotkeys($runTimeCommand);
-
- for ($hotkey in $hotkeys) {
- textScrollList -edit -append $hotkey HotkeyEditorHotkeyTextScrollList;
- }
-
- updateRemoveHotkeyButton();
- }
-
- proc enableNewHotkeyArea(int $enable)
- //
- // Description:
- // Update the enable state of the new hotkey assignment UI.
- //
- {
- text -edit -enable $enable HotkeyEditorKeyLabel;
- textField -edit -enable $enable HotkeyEditorKeyField;
- iconTextButton -edit -enable $enable HotkeyEditorKeyPopupMenuButton;
- text -edit -enable $enable HotkeyEditorModifierLabel;
- checkBox -edit -enable $enable HotkeyEditorCtrlCheckBox;
- checkBox -edit -enable $enable HotkeyEditorAltCheckBox;
- if(`about -macOS`){
- checkBox -edit -enable $enable HotkeyEditorCmdCheckBox;
- }
- text -edit -enable $enable HotkeyEditorDirectionLabel;
- radioButton -edit -enable $enable HotkeyEditorPressRadioButton;
- radioButton -edit -enable $enable HotkeyEditorReleaseRadioButton;
- text -edit -enable $enable HotkeyEditorRepeatableLabel;
- checkBox -edit -enable $enable HotkeyEditorRepeatableCheckBox;
- button -edit -enable $enable HotkeyEditorAssignHotkeyButton;
- button -edit -enable $enable HotkeyEditorQueryHotkeyButton;
- button -edit -enable $enable HotkeyEditorFindHotkeyButton;
- }
-
- proc setQueryHotkeyText(string $label)
- //
- // Description:
- // Set the query text message.
- //
- {
- text -edit -label $label HotkeyEditorQueryResultText;
- }
-
- proc int updateQueryHotkeyText()
- //
- // Description:
- // Update the text that displays the current hotkey mapping.
- //
- // Returns:
- // True if the query was successful, false otherwise. A
- // query may be unsuccessful if the user enters an invalid
- // value in the key field.
- //
- {
- int $result = false, $cmd=0;
-
- string $label = "\"";
- string $key = `textField -query -text HotkeyEditorKeyField`;
- int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
- int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
- int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
- if(`about -macOS`){
- $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
- }
-
- if ("" == $key || !isValidKey($key)) {
- $result = false;
-
- } else {
- $result = true;
-
- if ($ctrl) {
- if (`about -mac`) {
- $label += ("control+");
- }
- else {
- $label += ("Ctrl+");
- }
- }
- if ($alt) {
- if (`about -mac`) {
- $label += ("option+");
- }
- else {
- $label += ("Alt+");
- }
- }
- if($cmd){
- $label += ("command+");
- }
-
- $label += $key;
-
- if (!$press) {
- $label += " Release";
- }
-
- $label += "\" is assigned to:\n ";
-
- string $command = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
-
- if ("" == $command) {
- $label += "Nothing";
- } else {
- $label += $command;
- }
-
- setQueryHotkeyText($label);
- }
-
- return $result;
- }
-
- proc updateCommandTextScrollList(string $command)
- //
- // Description:
- // Fill in the command list with all the commands that belong to
- // the current selected category.
- //
- // If a command argument is passed in then make sure that command
- // is selected and visible in the list.
- //
- {
- string $list = "HotkeyEditorCommandTextScrollList";
- string $selectedCategory[], $category, $runTimeCommands[];
- int $index, $numberOfItems, $numberOfLines, $showItem;
-
- waitCursor -state on;
-
- $selectedCategory = `textScrollList -query
- -selectItem HotkeyEditorCategoryTextScrollList`;
-
- if (1 == size($selectedCategory)) {
- if ("Uncategorized" == $selectedCategory[0]) {
- $selectedCategory[0] = "";
- }
-
- if (0 < `textScrollList -query -numberOfItems $list`) {
- textScrollList -edit -removeAll $list;
- }
-
- $runTimeCommands = `runTimeCommand -query -commandArray`;
- for ($index = 0; $index < size($runTimeCommands); $index++) {
- $category = `runTimeCommand -query -category $runTimeCommands[$index]`;
- if ($selectedCategory[0] == $category) {
- textScrollList -edit -append $runTimeCommands[$index] $list;
- }
- }
- }
-
- if ("" == $command) {
- //
- // Select the first command.
- //
- if (0 < `textScrollList -query -numberOfItems $list`) {
- textScrollList -edit -selectIndexedItem 1 $list;
- }
-
- } else {
- //
- // Select the specified command.
- //
- textScrollList -edit -selectItem $command $list;
- }
-
- updateCurrentHotkeys();
- updateCommandInfo();
- updateCommandButtons();
-
- waitCursor -state off;
- }
-
- proc updateCategoryPopupMenu()
- //
- // Description:
- // Fill in the category popup menu with all the categories.
- //
- {
- string $categories[] = `textScrollList -query -allItems
- HotkeyEditorCategoryTextScrollList`;
- int $index, $numberOfCategories = size($categories);
-
- popupMenu -edit -deleteAllItems HotkeyEditorCategoryPopupMenu;
-
- setParent -menu HotkeyEditorCategoryPopupMenu;
-
- for ($index = 0; $index < $numberOfCategories; $index++) {
- menuItem -label $categories[$index]
- -enableCommandRepeat false
- -command ("hotkeyEditorCategoryPopupMenuSelect \"" +
- $categories[$index] + "\"");
- }
- }
-
- proc updateKeyPopupMenu()
- //
- // Description:
- // Fill in the key popup menu with all the special keys.
- //
- {
- string $keys[];
- int $index, $numberOfKeys;
- string $keys1[] = {"Up", "Down", "Left", "Right",
- "Page_Up", "Page_Down", "Home","End",
- "Return", "Space",
- "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
- "F9", "F10", "F11", "F12" };
-
- string $keys2[] = {"Up", "Down", "Left", "Right",
- "Page_Up", "Page_Down", "Home", "End", "Insert",
- "Return", "Space",
- "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
- "F9", "F10", "F11", "F12" };
- if (`about -mac`)
- {
- $numberOfKeys = size($keys1);
- for($index = 0; $index < $numberOfKeys; $index++)
- {
- $keys[$index] = $keys1[$index];
- }
- }
- else
- {
- $numberOfKeys = size($keys2);
- for($index = 0; $index < $numberOfKeys; $index++)
- {
- $keys[$index] = $keys2[$index];
- }
- }
-
- $numberOfKeys = size($keys);
-
- popupMenu -edit -deleteAllItems HotkeyEditorKeyPopupMenu;
-
- setParent -menu HotkeyEditorKeyPopupMenu;
-
- for ($index = 0; $index < $numberOfKeys; $index++) {
- menuItem -label $keys[$index] -enableCommandRepeat false
- -command ("hotkeyEditorKeyPopupMenuSelect " + $keys[$index]);
-
- // Throw in some separator items.
- //
- if (`about -mac`)
- {
- if ("Right" == $keys[$index] || "Home" == $keys[$index] ||
- "Space" == $keys[$index])
- {
- menuItem -divider true;
- }
- }
- else
- {
- if ("Right" == $keys[$index] || "Insert" == $keys[$index] ||
- "Space" == $keys[$index])
- {
- menuItem -divider true;
- }
- }
- }
- }
-
- proc removeHotkey(string $hotkey)
- //
- // Description:
- // Remove a hotkey assignment.
- //
- // Notes:
- // This procedure may be called as a result of deleting a runTimeCommand
- // that is attached to a custom Marking Menu (via the Marking Menu
- // Editor). The Hotkey Editor may or may not exist in this case.
- // Therefore DO NOT attempt to update any Hotkey Editor UI within this
- // function. It is the responsibility of the calling function to
- // handle any required updating.
- //
- {
- // Convert the hotkey string into its parameter elements.
- //
- // A hotkey string may look something like the following:
- //
- // a
- // Ctrl+z
- // Alt+N Release
- // Ctrl+Alt+b
- // Ctrl+Alt+b Release
- // In case of MAC
- // a
- // Ctrl+z
- //
- // From this string determine the 3 integer values that will
- // reflect the Ctrl and Alt modifier state and the key
- // direction (ie. press or release). We also want a string
- // that contains only the key value.
- //
- // First, break down the string into tokens. Tokens are
- // separated by white space.
- //
- string $token[], $plusString;
- int $numberOfTokens, $lastNumber, $lastButNum ;
- if(size($hotkey) > 1){
- $lastNumber = size($hotkey);
- $lastButNum = size($hotkey)-1;
- $plusString = `substring $hotkey $lastButNum $lastNumber`;
- }
-
- if($plusString == "++" ){
- $numberOfTokens = `tokenize $hotkey " +" $token`;
- $token[$numberOfTokens++] = "+";
- }else{
- if($hotkey == "+"){
- $numberOfTokens = 1;
- $token[0] = $hotkey;
- }else{
- $numberOfTokens = `tokenize $hotkey " +" $token`;
- }
- }
-
- string $key;
- int $ctrl = 0, $alt = 0, $press = 1, $cmd = 0;
-
- if (`about -mac`)
- {
- if (1 == $numberOfTokens) {
- //
- // Only one token. String contains the key only.
- // Both modifiers are off and the key direction is
- // press.
- //
- $key = $token[0];
-
- } else if (2 == $numberOfTokens) {
- //
- // Two tokens. String is either a key release or
- // a key with a single modifier.
- //
- if ("Release" == $token[1]) {
- //
- // Key release.
- //
- $key = $token[0];
- $press = 0;
-
- } else {
- //
- // Key and single modifier.
- //
- $key = $token[1];
- if ("control" == $token[0]) $ctrl = 1;
- else if("option" == $token[0]) $alt = 1;
- else $cmd = 1;
- }
-
- } else if (3 == $numberOfTokens) {
- //
- // Three tokens. String is either a key release with
- // a single modifier or a key with both modifiers.
- //
- if ("Release" == $token[2]) {
- //
- // Key release with single modifier.
- //
- $key = $token[1];
- $press = 0;
- if ("control" == $token[0]) $ctrl = 1;
- else if("option" == $token[0]) $alt = 1;
- else $cmd = 1;
-
- } else {
- //
- // Key press with both modifiers.
- //
- $key = $token[2];
- if((("control" == $token[0]) && ("option" == $token[1])) || (("control" == $token[1]) && ("option" == $token[0]))){
- $ctrl = 1;
- $alt = 1;
- }else if ((("control" == $token[0]) && ("command" == $token[1])) || (("control" == $token[1]) && ("command" == $token[0])) ){
- $ctrl = 1;
- $cmd = 1;
- }else{
- $alt = 1;
- $cmd = 1;
- }
- }
-
- } else if (4 == $numberOfTokens){
- if ("Release" == $token[3]) {
- //
- // Key release with single modifier.
- //
- $key = $token[2];
- $press = 0;
- if((("control" == $token[0]) && ("option" == $token[1])) || (("control" == $token[1]) && ("option" == $token[0]))){
- $ctrl = 1;
- $alt = 1;
- }else if ((("control" == $token[0]) && ("command" == $token[1])) || (("control" == $token[1]) && ("command" == $token[0])) ){
- $ctrl = 1;
- $cmd = 1;
- }else{
- $alt = 1;
- $cmd = 1;
- }
-
- } else {
- //
- // Key press with both modifiers.
- //
- $key = $token[3];
- if((("control" == $token[0]) && ("option" == $token[1]) && ("command" != $token[2])) ||
- (("control" == $token[1]) && ("option" == $token[0]) && ("command" != $token[2])) ||
- (("control" == $token[1]) && ("option" == $token[2]) && ("command" != $token[0])) ||
- (("control" == $token[2]) && ("option" == $token[1]) && ("command" != $token[0])) ){
- $ctrl = 1;
- $alt = 1;
- }else if ( (("control" == $token[0]) && ("command" == $token[1]) && ("option" != $token[2])) ||
- (("control" == $token[1]) && ("command" == $token[0]) && ("option" != $token[2])) ||
- (("control" == $token[1]) && ("command" == $token[2]) && ("option" != $token[0])) ||
- (("control" == $token[2]) && ("command" == $token[1]) && ("option" != $token[0])) ){
- $ctrl = 1;
- $cmd = 1;
- }else if ( (("option" == $token[0]) && ("command" == $token[1]) && ("control" != $token[2])) ||
- (("option" == $token[1]) && ("command" == $token[0]) && ("control" != $token[2])) ||
- (("option" == $token[1]) && ("command" == $token[2]) && ("control" != $token[0])) ||
- (("option" == $token[2]) && ("command" == $token[1]) && ("control" != $token[0])) ) {
- $alt = 1;
- $cmd = 1;
- }else{
- $alt = 1;
- $cmd = 1;
- $ctrl = 1;
- }
- }
- }else{
- //
- // All four tokens. String is key release with both
- // modifiers.
- //
- $ctrl = 1;
- $alt = 1;
- $cmd = 1;
- $key = $token[3];
- $press = 0;
- }
- }
- else{
- if (1 == $numberOfTokens) {
- //
- // Only one token. String contains the key only.
- // Both modifiers are off and the key direction is
- // press.
- //
- $key = $token[0];
-
- } else if (2 == $numberOfTokens) {
- //
- // Two tokens. String is either a key release or
- // a key with a single modifier.
- //
- if ("Release" == $token[1]) {
- //
- // Key release.
- //
- $key = $token[0];
- $press = 0;
-
- } else {
- //
- // Key and single modifier.
- //
- $key = $token[1];
- if ("Ctrl" == $token[0]) $ctrl = 1;
- else $alt = 1;
- }
-
- } else if (3 == $numberOfTokens) {
- //
- // Three tokens. String is either a key release with
- // a single modifier or a key with both modifiers.
- //
- if ("Release" == $token[2]) {
- //
- // Key release with single modifier.
- //
- $key = $token[1];
- $press = 0;
- if ("Ctrl" == $token[0]) $ctrl = 1;
- else $alt = 1;
-
- } else {
- //
- // Key press with both modifiers.
- //
- $key = $token[2];
- $ctrl = 1;
- $alt = 1;
- }
-
- } else {
- //
- // All four tokens. String is key release with both
- // modifiers.
- //
- $ctrl = 1;
- $alt = 1;
- $key = $token[2];
- $press = 0;
- }
- }
-
- // To remove a hotkey assignment simply set the hotkey command flag
- // -name or -releaseName to an empty string.
- //
- string $hotkeyCmd;
- $hotkeyCmd = constructHotkeyCommand($key, $ctrl, $alt, $cmd, $press, false, "");
- eval ($hotkeyCmd);
- }
-
- proc deleteRunTimeCommand(string $command)
- //
- // Description:
- // Delete the given runTimeCommand. Also cleanup, remove, and/or
- // delete any nameCommands and hotkeys that use this runTimeCommand.
- //
- // Notes:
- // This procedure may be called as a result of deleting a runTimeCommand
- // that is attached to a custom Marking Menu (via the Marking Menu
- // Editor). The Hotkey Editor may or may not exist in this case.
- // Therefore DO NOT attempt to update any Hotkey Editor UI within this
- // function. It is the responsibility of the calling function to
- // handle any required updating.
- //
- {
- if (`runTimeCommand -exists $command` &&
- !`runTimeCommand -query -default $command`) {
-
- int $mustUpdateCurrentHotkeys = false;
-
- //
- // Determine all the hotkeys pointing to this command.
- //
- string $hotkeys[] = getAllHotkeys($command);
-
- if (size($hotkeys) > 0) {
- for ($hotkey in $hotkeys) {
- removeHotkey($hotkey);
- }
- }
-
- // Determine the nameCommand associated with this command.
- //
- string $nameCommand = $command + "NameCommand";
- int $numberOfNameCommands = `assignCommand -query -numElements`;
- for ($index = 1; $index <= $numberOfNameCommands; $index++) {
- if ($nameCommand == `assignCommand -query -name $index`) {
- assignCommand -edit -delete $index;
- break;
- }
- }
-
- // Now delete the command.
- //
- runTimeCommand -edit -delete $command;
- }
- }
-
- proc createCommandListArea(string $parent)
- //
- // Description:
- // Create the UI for the category list and command list.
- //
- {
- setParent $parent;
-
- // Category list.
- //
- string $categoryFrame = `frameLayout -label "Categories"
- -borderVisible false`;
- string $categoryForm = `formLayout`;
- string $categoryList = `textScrollList
- -selectCommand ("hotkeyEditorCategoryTextScrollListSelect")
- HotkeyEditorCategoryTextScrollList`;
- setParent ..;
- setParent ..;
-
- // Command list.
- //
- string $commandFrame = `frameLayout -label "Commands"
- -borderVisible false`;
- string $commandForm = `formLayout`;
- string $commandList = `textScrollList
- -selectCommand ("hotkeyEditorCommandTextScrollListSelect")
- HotkeyEditorCommandTextScrollList`;
- setParent ..;
- setParent ..;
-
- // Get all the categories.
- //
- string $categories[] = `runTimeCommand -query -categoryArray`;
- int $index, $numberOfCategories = size($categories);
-
- int $foundUserCategory = false;
-
- for ($index = 0; $index < $numberOfCategories; $index++) {
- textScrollList -edit -append $categories[$index] $categoryList;
- if ("User" == $categories[$index]) {
- $foundUserCategory = true;
- }
- }
-
- // Create a default User category.
- //
- if (!$foundUserCategory) {
- textScrollList -edit -append "User" $categoryList;
- }
-
- // Are there any runTimeCommands that don't have a category specified?
- //
- // Eventually, there shouldn't be but until they all get one list them
- // in the "Uncategorized" category.
- //
- string $runTimeCommands[] = `runTimeCommand -query -commandArray`;
- for ($index = 0; $index < size($runTimeCommands); $index++) {
- if ("" == `runTimeCommand -query -category $runTimeCommands[$index]`) {
- textScrollList -edit -append "Uncategorized" $categoryList;
- break;
- }
- }
-
- if (0 < `textScrollList -query -numberOfItems $categoryList`) {
- textScrollList -edit -selectIndexedItem 1 $categoryList;
- }
-
- formLayout -edit
- -attachForm $categoryList "top" 0
- -attachForm $categoryList "left" 0
- -attachForm $categoryList "bottom" 0
- -attachForm $categoryList "right" 0
- $categoryForm;
-
- formLayout -edit
- -attachForm $commandList "top" 0
- -attachForm $commandList "left" 0
- -attachForm $commandList "bottom" 0
- -attachForm $commandList "right" 0
- $commandForm;
-
- formLayout -edit
- -attachForm $categoryFrame "top" 0
- -attachForm $categoryFrame "left" 0
- -attachForm $categoryFrame "bottom" 0
- -attachNone $categoryFrame "right"
- -attachForm $commandFrame "top" 0
- -attachControl $commandFrame "left" 5 $categoryFrame
- -attachForm $commandFrame "bottom" 0
- -attachForm $commandFrame "right" 0
- $parent;
- }
-
- proc createCommandInfoArea(string $parent)
- //
- // Description:
- // Create the UI for listing all the information pertaining to
- // the current runTimeCommand.
- //
- {
- setParent $parent;
-
- // All the buttons.
- //
- string $buttonForm = `columnLayout -adjustableColumn true`;
- string $createButton = `button -label "New"
- -recomputeSize false -width 100
- -command ("hotkeyEditorCreateCommand")
- HotkeyEditorCreateCommandButton`;
- string $editButton = `button -label "Edit"
- -command ("hotkeyEditorEditCommand")
- HotkeyEditorEditCommandButton`;
- string $deleteButton = `button -label "Delete"
- -command ("hotkeyEditorDeleteCommand")
- HotkeyEditorDeleteCommandButton`;
- separator -style "none" -height 10;
- string $acceptButton = `button -label "Accept"
- -command ("hotkeyEditorAcceptCommand")
- HotkeyEditorAcceptCommandButton`;
- string $cancelButton = `button -label "Cancel"
- -command ("hotkeyEditorCancelCommand")
- HotkeyEditorCancelCommandButton`;
- separator -style "none" -height 10;
- string $searchButton = `button -label "Search..."
- -command ("hotkeyEditorSearchForRunTimeCommand")
- HotkeyEditorSearchButton`;
- string $helpButton = `button -label "Help..."
- -command ("showHelp HotkeyEditor")
- HotkeyEditorHelpButton`;
-
- // The labels and fields.
- //
- setParent $parent;
- string $info = `columnLayout -adjustableColumn true`;
- rowLayout
- -numberOfColumns 2
- -adjustableColumn 2
- -columnAlign 1 "right"
- -columnWidth 1 80
- -columnWidth 2 300
- -columnAttach 1 "both" 5
- -columnAttach 2 "both" 0;
- text -label "Name";
- textField -editable false HotkeyEditorNameField;
- setParent ..;
-
- rowLayout
- -numberOfColumns 2
- -adjustableColumn 2
- -columnAlign 1 "right"
- -columnWidth 1 80
- -columnWidth 2 300
- -columnAttach 1 "both" 5
- -columnAttach 2 "both" 0;
- text -label "Description";
- textField -editable false HotkeyEditorDescriptionField;
- setParent ..;
-
- rowLayout
- -numberOfColumns 3
- -columnAlign 1 "right"
- -columnWidth 1 80
- -columnWidth 2 200
- -columnAttach 1 "both" 5
- -columnAttach 2 "both" 0;
- text -label "Category";
- textField -editable false HotkeyEditorCategoryField;
- iconTextButton -image1 "popupMenuIcon.xpm" -height 26 -width 18
- HotkeyEditorCategoryPopupMenuButton;
- popupMenu -button 1 HotkeyEditorCategoryPopupMenu;
- setParent ..;
-
- rowLayout
- -numberOfColumns 2
- -adjustableColumn 2
- -columnAlign 1 "right"
- -columnWidth 1 80
- -columnWidth 2 300
- -columnAttach 1 "both" 5
- -columnAttach 2 "both" 0;
- text -label "Command";
- scrollField -height 160 -editable false
- HotkeyEditorCommandField;
- setParent ..;
-
- formLayout -edit
- -numberOfDivisions 100
- -attachForm $info "top" 0
- -attachForm $info "left" 0
- -attachForm $info "bottom" 0
- -attachControl $info "right" 5 $buttonForm
- -attachForm $buttonForm "top" 0
- -attachNone $buttonForm "left"
- -attachForm $buttonForm "bottom" 0
- -attachForm $buttonForm "right" 0
- $parent;
- }
-
- proc createCurrentHotkeyArea(string $parent)
- //
- // Description:
- // Create the UI for listing the hotkeys assigned to the
- // current command.
- //
- {
- setParent $parent;
-
- string $hotkeyFrame = `frameLayout -label "Current Hotkeys"
- -borderVisible false`;
- string $hotkeyForm = `formLayout`;
-
- string $list = `textScrollList -numberOfRows 3
- -selectCommand ("hotkeyEditorHotkeyTextScrollListSelect")
- HotkeyEditorHotkeyTextScrollList`;
-
- // set the textScrollList height so that, the scroll bar
- // shows the scrollBox when there are enough contents to scroll
- //
- if(`about -mac`) {
- textScrollList -e -h 100 HotkeyEditorHotkeyTextScrollList;
- }
-
- string $removeButton = `button -label "Remove"
- -command ("hotkeyEditorRemoveHotkey")
- HotkeyEditorRemoveHotkeyButton`;
-
- string $restoreButton = `button -label "Restore Defaults"
- -command ("hotkeyEditorRestoreDefaultHotkeys")
- HotkeyEditorRestoreDefaultHotkeysButton`;
-
- string $listAllButton = `button -label "List All..."
- -command ("hotkeyEditorListAllHotkeys")
- HotkeyEditorListAllHotkeysButton`;
-
- formLayout -edit
- -attachForm $list "top" 0
- -attachForm $list "left" 0
- -attachNone $list "bottom"
- -attachForm $list "right" 0
-
- -attachControl $removeButton "top" 5 $list
- -attachForm $removeButton "left" 5
- -attachNone $removeButton "bottom"
- -attachForm $removeButton "right" 5
-
- -attachControl $listAllButton "top" 5 $removeButton
- -attachForm $listAllButton "left" 5
- -attachNone $listAllButton "bottom"
- -attachPosition $listAllButton "right" 2 50
-
- -attachControl $restoreButton "top" 5 $removeButton
- -attachPosition $restoreButton "left" 2 50
- -attachNone $restoreButton "bottom"
- -attachForm $restoreButton "right" 5
-
- $hotkeyForm;
-
- formLayout -edit
- -attachForm $hotkeyFrame "top" 0
- -attachForm $hotkeyFrame "left" 0
- -attachForm $hotkeyFrame "bottom" 0
- -attachForm $hotkeyFrame "right" 0
- $parent;
- }
-
- proc createNewHotkeyArea(string $parent)
- //
- // Description:
- // Create the UI for assigning new hotkeys.
- //
- {
- setParent $parent;
-
- frameLayout -label "Assign New Hotkey" -labelAlign "center"
- -borderStyle "etchedIn" -marginWidth 5 -marginHeight 5;
-
- columnLayout -adjustableColumn true;
-
- // Key field and popup menu.
- //
- if(`about -macOS`){
- /*
- rowColumnLayout -numberOfColumns 4
- -columnWidth 1 70
- -columnWidth 2 60
- -columnWidth 3 60
- -columnWidth 4 60
- -columnAlign 1 "right"
- -columnAlign 2 "left"
- -columnAlign 3 "left"
- -columnAlign 4 "left"
- -columnAttach 4 "left" 0;
- */
- rowColumnLayout -numberOfColumns 4
- -columnWidth 1 70
- -columnWidth 2 70
- -columnWidth 3 70
- -columnWidth 4 60
- -columnAlign 1 "right"
- -columnAlign 2 "left"
- -columnAlign 3 "left"
- -columnAlign 4 "left"
- -columnAttach 4 "left" 0;
-
- }else{
- rowColumnLayout -numberOfColumns 3
- -columnWidth 1 70
- -columnWidth 2 80
- -columnWidth 3 80
- -columnAlign 1 "right"
- -columnAlign 2 "left"
- -columnAlign 3 "left"
- -columnAttach 3 "left" 0;
- }
-
- text -label "Key" HotkeyEditorKeyLabel;
- textField -changeCommand ("hotkeyEditorHotkeyKeyFieldChange")
- HotkeyEditorKeyField;
- iconTextButton -image1 "popupMenuIcon.xpm" -height 26 -width 18
- HotkeyEditorKeyPopupMenuButton;
- popupMenu -button 1 HotkeyEditorKeyPopupMenu;
- if(`about -macOS`){
- text -label "";
- }
- // Modifier check boxes.
- //
- text -label "Modifier" HotkeyEditorModifierLabel;
- if (`about -macOS`) {
- checkBox -label "control" -changeCommand ("hotkeyEditorHotkeyCtrlCheckBoxChange")
- HotkeyEditorCtrlCheckBox;
- }
- else {
- checkBox -label "Ctrl" -changeCommand ("hotkeyEditorHotkeyCtrlCheckBoxChange")
- HotkeyEditorCtrlCheckBox;
- }
- if(`about -macOS`){
- checkBox -label "option" -changeCommand ("hotkeyEditorHotkeyAltCheckBoxChange")
- HotkeyEditorAltCheckBox;
- }else{
- checkBox -label "Alt" -changeCommand ("hotkeyEditorHotkeyAltCheckBoxChange")
- HotkeyEditorAltCheckBox;
- }
- if(`about -macOS`) {
- checkBox -label "command" -changeCommand ("hotkeyEditorHotkeyCmdCheckBoxChange")
- HotkeyEditorCmdCheckBox;
- }
-
- // Key press vs. release radio buttons.
- //
- text -label "Direction" HotkeyEditorDirectionLabel;
- radioCollection;
- radioButton -label "Press" -select
- -changeCommand ("hotkeyEditorHotkeyPressRadioButtonChange")
- HotkeyEditorPressRadioButton;
- radioButton -label "Release"
- -changeCommand ("hotkeyEditorHotkeyReleaseRadioButtonChange")
- HotkeyEditorReleaseRadioButton;
-
- setParent ..;
-
- separator -height 5 -style "none";
-
- // Repeatable check box.
- //
- rowColumnLayout -numberOfColumns 2
- -columnWidth 1 15
- -columnWidth 2 200
- -columnAlign 1 "right"
- -columnAlign 2 "left";
- text -label " " HotkeyEditorRepeatableLabel;
- checkBox -label "Add to Recent Command List"
- -align "left" HotkeyEditorRepeatableCheckBox;
- setParent ..;
-
-
- // Text for query results.
- //
- text -align "left" -recomputeSize false -label "" -height 47
- HotkeyEditorQueryResultText;
-
- // The buttons.
- //
- string $buttons = `formLayout`;
- string $assign = `button -label "Assign"
- -command ("hotkeyEditorAssignHotkey")
- HotkeyEditorAssignHotkeyButton`;
- string $query = `button -label "Query"
- -command ("hotkeyEditorQueryHotkey")
- HotkeyEditorQueryHotkeyButton`;
- string $find = `button -label "Find"
- -command ("hotkeyEditorFindHotkey")
- HotkeyEditorFindHotkeyButton`;
- setParent ..;
-
- formLayout -edit
- -numberOfDivisions 100
- -attachForm $assign "top" 0
- -attachForm $assign "left" 0
- -attachForm $assign "bottom" 0
- -attachPosition $assign "right" 2 33
- -attachForm $query "top" 0
- -attachPosition $query "left" 2 33
- -attachForm $query "bottom" 0
- -attachPosition $query "right" 2 66
- -attachForm $find "top" 0
- -attachPosition $find "left" 2 66
- -attachForm $find "bottom" 0
- -attachForm $find "right" 0
- $buttons;
- }
-
- proc createButtonsArea(string $parent)
- //
- // Description:
- // Create the buttons for the window.
- //
- {
- setParent $parent;
-
- string $saveButton = `button -label "Save"
- -command ("hotkeyEditorSave")
- HotkeyEditorSaveButton`;
- string $closeButton = `button -label "Close"
- -command ("hotkeyEditorClose")
- HotkeyEditorCloseButton`;
-
- formLayout -edit
- -numberOfDivisions 100
- -attachForm $saveButton "top" 0
- -attachForm $saveButton "left" 0
- -attachForm $saveButton "bottom" 0
- -attachPosition $saveButton "right" 2 50
- -attachForm $closeButton "top" 0
- -attachPosition $closeButton "left" 2 50
- -attachForm $closeButton "bottom" 0
- -attachForm $closeButton "right" 0
- $parent;
- }
-
- proc resetCreateOrEditMode()
- //
- // Description:
- // Reset the edit mode.
- //
- {
- global int $gHotkeyEditorInCreateMode;
- global int $gHotkeyEditorInEditMode;
-
- $gHotkeyEditorInCreateMode = false;
- $gHotkeyEditorInEditMode = false;
-
- updateCommandInfo();
- updateCommandButtons();
- enableNewHotkeyArea(true);
- }
-
- global proc string[] getAllValidKeys()
- //
- // Description:
- // Return a string array containing all the valid keys
- // that a hotkey may be assigned to.
- //
- {
- int $index, $numberOfKeys;
- string $hotkeys[];
- string $hotkeys1[] = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
- "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z",
-
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z",
-
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- ")", "!", "@", "#", "$", "%", "^", "&", "*", "(",
-
- "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
- "F9", "F10", "F11", "F12",
-
- "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/",
- "~", "_", "+", "{", "}", "|", ":", "\"", "<", ">", "?",
-
- "Up", "Down", "Left", "Right",
-
- "Page_Up", "Page_Down", "Home", "End",
- "Return", "Space"
- };
- string $hotkeys2[] = {
- "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
- "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
- "u", "v", "w", "x", "y", "z",
-
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
- "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
- "U", "V", "W", "X", "Y", "Z",
-
- "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- ")", "!", "@", "#", "$", "%", "^", "&", "*", "(",
-
- "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
- "F9", "F10", "F11", "F12",
-
- "`", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/",
- "~", "_", "+", "{", "}", "|", ":", "\"", "<", ">", "?",
-
- "Up", "Down", "Left", "Right",
-
- "Page_Up", "Page_Down", "Home", "End", "Insert",
- "Return", "Space"
- };
- if (`about -mac`)
- {
- $numberOfKeys = size($hotkeys1);
- for($index = 0; $index < $numberOfKeys; $index++)
- {
- $hotkeys[$index] = $hotkeys1[$index];
- }
- }
- else
- {
-
- $numberOfKeys = size($hotkeys2);
- for($index = 0; $index < $numberOfKeys; $index++)
- {
- $hotkeys[$index] = $hotkeys2[$index];
- }
- }
-
- return $hotkeys;
- }
-
- global proc string getHotkeyCommandNew (
- string $key,
- int $ctrl,
- int $alt,
- int $command,
- int $press)
- //
- // Description:
- // Return the command that will be executed if the specified hotkey
- // is invoked.
- //
- // Arguments:
- // key - The key.
- // ctrl - State of the Ctrl modifier.
- // alt - State of the Alt modifier.
- // press - Key direction. Specify true for key press, false for
- // key release.
- //
- // Returns:
- // A string containing the command that will be executed. An empty
- // string is returned if no command is attached to the hotkey.
- //
- // Examples:
- // // Determine the press command attached to the hotkey Ctrl a.
- // //
- // string $press = getHotkeyCommand("a", true, false, true);
- //
- // // Determine the release command attached to the hotkey Alt Z.
- // //
- // string $release = getHotkeyCommand("Z", false, true, false);
- //
- {
- string $result = "";
- string $nameCommand = "";
-
- string $hotkeyQueryCommand = "hotkey -query ";
- if ($ctrl) $hotkeyQueryCommand += "-ctl ";
- if ($alt) $hotkeyQueryCommand += "-alt ";
- if($command) $hotkeyQueryCommand += "-cmd ";
- if ($press) $hotkeyQueryCommand += "-name ";
- else $hotkeyQueryCommand += "-releaseName ";
-
- if ("\"" == $key || "\\" == $key) {
- //
- // Need to preceed double quote and backslash characters
- // with a backslash.
- //
- $hotkeyQueryCommand += ("\"\\" + $key + "\"");
-
- } else if ("-" == $key) {
- //
- // Can't pass a dash as a string argument to a command
- // because it gets interpreted as the beginning of another
- // flag. Use the word "Dash" instead.
- //
- $hotkeyQueryCommand += ("Dash");
-
- } else {
- //
- // Surround the string argument with quotes so that
- // non-alphabetic characters get treated as strings
- // properly.
- //
- $hotkeyQueryCommand += ("\"" + $key + "\"");
- }
- $nameCommand = eval($hotkeyQueryCommand);
-
- if ("" != $nameCommand) {
- //
- // Get the runTimeCommand this nameCommand points to.
- //
- string $runTimeCommand = getRunTimeCommandFromNameCommand($nameCommand);
- if ("" != $runTimeCommand) {
- $result = $runTimeCommand;
-
- } else {
- //
- // This is a name command that hasn't been converted to use
- // a runTimeCommand yet.
- //
- $result = $nameCommand;
- }
- }
-
- return $result;
- }
-
- global proc string getHotkeyCommand(
- string $key,
- int $ctrl,
- int $alt,
- int $cmd,
- int $press)
- {
- if(`about -mac`){
- return (getHotkeyCommandNew ($key, $ctrl, $alt, $cmd, $press));
- }
-
- return (getHotkeyCommandNew ($key, $ctrl, $alt, false, $press));
- }
-
- global proc string getRunTimeCommandFromNameCommand(string $nameCommand)
- //
- // Description:
- // Return the runTimeCommand that is invoked by the specified
- // nameCommand.
- //
- {
- string $result = "";
- int $index, $numberOfNameCommands;
-
- $numberOfNameCommands = `assignCommand -query -numElements`;
- for ($index = 1; $index <= $numberOfNameCommands; $index++) {
- if ($nameCommand == `assignCommand -query -name $index`) {
- $result = `assignCommand -query -command $index`;
- break;
- }
- }
-
- if (!`runTimeCommand -exists $result`) $result = "";
-
- return $result;
- }
-
- global proc hotkeyEditorCategoryTextScrollListSelect()
- //
- // Description:
- // This procedure is called whenever the user selects a category
- // in the list.
- //
- {
- resetCreateOrEditMode();
- updateCommandTextScrollList("");
- }
-
- global proc hotkeyEditorCommandTextScrollListSelect()
- //
- // Description:
- // This procedure is called whenever the user selects a command
- // in the list.
- //
- {
- resetCreateOrEditMode();
- updateCurrentHotkeys();
- updateCommandButtons();
- updateCommandInfo();
- }
-
- global proc hotkeyEditorHotkeyKeyFieldChange()
- //
- // Description:
- // This procedure is called whenever the user changes the value
- // in the key field.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
- global proc hotkeyEditorHotkeyCtrlCheckBoxChange()
- //
- // Description:
- // This procedure is called whenever the user turns on or
- // off the Ctrl check box.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
- global proc hotkeyEditorHotkeyAltCheckBoxChange()
- //
- // Description:
- // This procedure is called whenever the user turns on or
- // off the Alt check box.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
- global proc hotkeyEditorHotkeyCmdCheckBoxChange()
- //
- // Description:
- // This procedure is called whenever the user turns on or
- // off the Alt check box.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
-
- global proc hotkeyEditorHotkeyPressRadioButtonChange()
- //
- // Description:
- // This procedure is called whenever the user turns on or
- // off the Press radio button.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
- global proc hotkeyEditorHotkeyReleaseRadioButtonChange()
- //
- // Description:
- // This procedure is called whenever the user turns on or
- // off the Release radio button.
- //
- {
- if (!updateQueryHotkeyText()) {
- setQueryHotkeyText("");
- }
- }
-
- global proc hotkeyEditorHotkeyTextScrollListSelect()
- //
- // Description:
- // This procedure is called whenever the user selects a hotkey
- // in the list.
- //
- {
- resetCreateOrEditMode();
- updateRemoveHotkeyButton();
- }
-
- global proc hotkeyEditorCategoryPopupMenuSelect(string $category)
- //
- // Description:
- // This procedure is called whenever the user selects a category
- // from the popup menu.
- //
- {
- textField -edit -text $category HotkeyEditorCategoryField;
- }
-
- global proc hotkeyEditorKeyPopupMenuSelect(string $key)
- //
- // Description:
- // This procedure is called whenever the user selects a key
- // from the popup menu.
- //
- {
- textField -edit -text $key HotkeyEditorKeyField;
- hotkeyEditorQueryHotkey();
- }
-
- global proc hotkeyEditorCreateCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Create command button.
- //
- {
- global int $gHotkeyEditorInCreateMode;
-
- $gHotkeyEditorInCreateMode = true;
-
- updateCommandInfo();
- updateCommandButtons();
- enableNewHotkeyArea(false);
- }
-
- global proc hotkeyEditorEditCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Edit command button.
- //
- {
- global int $gHotkeyEditorInEditMode;
-
- $gHotkeyEditorInEditMode = true;
-
- updateCommandInfo();
- updateCommandButtons();
- enableNewHotkeyArea(false);
- }
-
- global proc hotkeyEditorDeleteCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Delete command button.
- //
- {
- string $command = getCurrentRunTimeCommand();
- string $list = "HotkeyEditorCommandTextScrollList";
-
- //
- // Remove the item from the list.
- //
- if ("" != $command) {
-
- // Confirm that the user really wants to delete the command.
- //
- // Fixes bug #126567.
- //
- string $message = "Delete the " + $command + " command?";
- $confirmResponse = `confirmDialog -button "Delete" -button "Cancel"
- -defaultButton "Delete" -cancelButton "Cancel"
- -message $message`;
-
- //
- // *** Return statement ***
- //
- if ("Delete" != $confirmResponse) return;
-
- deleteRunTimeCommand($command);
- textScrollList -edit -removeItem $command $list;
-
- // Select the first command in the list.
- //
- int $numberOfItems = `textScrollList -query -numberOfItems $list`;
- if ($numberOfItems > 0) {
- textScrollList -edit -selectIndexedItem 1 $list;
- textScrollList -edit -showIndexedItem 1 $list;
- }
-
- updateCommandInfo();
- updateCommandButtons();
- updateCurrentHotkeys();
- }
- }
-
- global proc hotkeyEditorAcceptCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Accept command button.
- //
- {
- global int $gHotkeyEditorInCreateMode;
- global int $gHotkeyEditorInEditMode;
-
- string $oldName, $name, $description, $command, $list;
- string $oldCategory, $category;
- string $runTimeCommand, $errorMessage;
- int $numberOfItems, $numberOfLines, $showItem;
-
- $oldName = getCurrentRunTimeCommand();
- $oldCategory = getCurrentCategory();
- $name = `textField -query -text HotkeyEditorNameField`;
- $description = `textField -query -text HotkeyEditorDescriptionField`;
- $command = `scrollField -query -text HotkeyEditorCommandField`;
- $category = `textField -query -text HotkeyEditorCategoryField`;
- $runTimeCommand = ("runTimeCommand " + $name);
- $list = "HotkeyEditorCommandTextScrollList";
-
- // Fix for bug #132763. Allowing the user to have a run time command execute
- // itself will result in an infinite loop when the command is called.
- //
- if ($name == $command) {
- confirmDialog -button "Close" -defaultButton "Close" -cancelButton "Close"
- -message "The name must not be the same as the command.";
- return;
- }
-
- if ($gHotkeyEditorInEditMode) {
-
- // Is the category name valid?
- //
- if ($category != $oldCategory && !isValidCategory($category)) {
- $errorMessage = "Select a category from the popup menu or enter"
- + " a value that begins with a character\nand is followed by"
- + " alphanumeric characters, underscores, or spaces.";
- }
-
- if ("" == $errorMessage && $name != $oldName) {
- //
- // We can't really rename commands so we have to create a new
- // command with the given name and then delete the old one.
- //
- if ("" != $name && isValidName($name) && isUniqueName($name)) {
-
- eval ($runTimeCommand);
- runTimeCommand -edit -delete $oldName;
-
- // Determine the old item's position in the list.
- //
- string $items[] = `textScrollList -query -allItems $list`;
- int $index, $count = size($items);
- for ($index = 0; $index < $count; $index++) {
- if ($oldName == $items[$index]) {
- break;
- }
- }
-
- if ($category == $oldCategory) {
-
- // Add our new item after the old item.
- //
- textScrollList -edit -appendPosition ($index + 1) $name $list;
-
- // Remove the old item from the list.
- //
- textScrollList -edit -removeItem $oldName $list;
- }
-
- } else if (!isValidName($name)) {
- //
- // Not a valid name.
- //
- $errorMessage = "The name must begin with an alphabetic"
- + " character or underscore. The remaining\ncharacters"
- + " must consist of alphanumeric characters or underscores.";
-
- } else if (!isUniqueName($name)) {
- $errorMessage = getNameErrorMessage($name);
- }
- }
-
- if ("" == $errorMessage) {
- runTimeCommand -edit
- -command $command
- -annotation $description
- -category $category
- $name;
- }
-
- } else {
- //
- // Validate the field values.
- //
- if ("" != $name && isValidName($name) && isUniqueName($name)
- && isValidCategory($category)) {
-
- eval ($runTimeCommand);
-
- runTimeCommand -edit
- -command $command
- -annotation $description
- -category $category
- $name;
-
- if ($category == $oldCategory) {
-
- // Add our item to the list.
- //
- textScrollList -edit -append $name -selectItem $name $list;
-
- // Make our newly added item visible within the list.
- //
- $numberOfItems = `textScrollList -query -numberOfItems $list`;
- $numberOfLines = `textScrollList -query -numberOfRows $list`;
- $showItem = $numberOfItems - $numberOfLines + 1;
- if ($showItem < 1) $showItem = 1;
- textScrollList -edit -showIndexedItem $showItem $list;
- }
-
- } else if (!isValidName($name)) {
- //
- // Not a valid name.
- //
- $errorMessage = "The name must begin with an alphabetic"
- + " character or underscore. The remaining\ncharacters"
- + " must consist of alphanumeric characters or underscores.";
-
- } else if (!isUniqueName($name)) {
- $errorMessage = getNameErrorMessage($name);
-
- } else if (!isValidCategory($category)) {
- $errorMessage = "Select a category from the popup menu or enter"
- + " a value that begins with a character\nand is followed by"
- + " alphanumeric characters, underscores, or spaces.";
- }
- }
-
- if ("" == $errorMessage) {
- $gHotkeyEditorInCreateMode = false;
- $gHotkeyEditorInEditMode = false;
-
- $list = "HotkeyEditorCategoryTextScrollList";
-
- if (!isExistingCategory($category)) {
- //
- // Add the category to the list.
- //
- textScrollList -edit -append $category -selectItem $category $list;
- }
-
- if ($category != $oldCategory) {
- //
- // Select the new category.
- //
- textScrollList -edit -selectItem $category $list;
-
- // Now update the command list.
- //
- updateCommandTextScrollList($name);
- }
-
- updateCommandInfo();
- updateCommandButtons();
- updateCurrentHotkeys();
- enableNewHotkeyArea(true);
-
- } else {
- confirmDialog -button "Close" -message $errorMessage
- -defaultButton "Close" -cancelButton "Close";
- }
- }
-
- global proc hotkeyEditorCancelCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Cancel command button.
- //
- {
- resetCreateOrEditMode();
- }
-
- global proc hotkeyEditorSearchForRunTimeCommand()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Search button.
- //
- {
- searchForRunTimeCommandWindow;
- }
-
- global proc hotkeyEditorAssignHotkey()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Assign hotkey button.
- //
- {
- int $cmd = 0;
-
- string $key = `textField -query -text HotkeyEditorKeyField`;
- int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
- int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
- int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
- int $repeat = `checkBox -query -value HotkeyEditorRepeatableCheckBox`;
-
- if(`about -macOS`){
- $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
- }
- string $runTimeCommand, $nameCommandName;
- int $nameCommandIndex;
- int $setUpReleaseHotkey = false;
-
- if ("" == $key || !isValidKey($key)) {
- $label = "You must enter a valid key\nin the Key field above.";
- text -edit -label $label HotkeyEditorQueryResultText;
-
- } else {
- string $existingCommand = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
- string $confirmResponse;
-
- if ("" != $existingCommand) {
-
- string $message = "The hotkey is already assigned to " + $existingCommand
- + ".\nDo you want to override this with your new hotkey assignment?";
- $confirmResponse = `confirmDialog -button "Assign" -button "Cancel"
- -defaultButton "Assign" -cancelButton "Cancel"
- -message $message`;
-
- //
- // *** Return statement ***
- //
- if ("Assign" != $confirmResponse) return;
- }
-
- // Check for dangling release hotkeys that could cause trouble for
- // the user. Bug #88549 and #137784.
- //
- // If the user assigns a press hotkey then check to see if there
- // was a release command attached to the same hotkey. The user
- // would not expect that their new command be executed on press
- // and their old release command be executed on release.
- //
- if ($press) {
- //
- // Check if there is a release command attached to the hotkey
- // as well.
- //
- $releaseCommand = getHotkeyCommand($key, $ctrl, $alt, $cmd, 0);
-
- if ("" != $releaseCommand) {
- $message = "The hotkey also has a release command assigned to " +
- $releaseCommand + ".\nThis assignment will be removed.";
- confirmDialog -button "OK" -defaultButton "OK" -cancelButton "OK"
- -message $message;
- $removeReleaseHotkeyCmd = constructHotkeyCommand(
- $key, $ctrl, $alt, $cmd, 0, 0, "");
- eval ($removeReleaseHotkeyCmd);
- }
- }
-
- $runTimeCommand = getCurrentRunTimeCommand();
- $nameCommandName = $runTimeCommand + "NameCommand";
- $nameCommandIndex = getNameCommand($nameCommandName);
-
- // Have we created a nameCommand object for this runTimeCommand
- // yet? If we have it will be have the same name as the runTimeCommand
- // with "NameCommand" appended to it. For example, a runTimeCommand
- // called "Example" will have a nameCommand object called
- // "ExampleNameCommand".
- //
- // Note that a runTimeCommand may have other default nameCommand
- // objects pointing to it (ie. set up in nameCommandSetup.mel).
- // We don't want to apply the hotkey to one of these.
- //
-
- if (0 == $nameCommandIndex) {
- //
- // Create a new nameCommand object.
- //
- // Note that nameCommand command requires the annotation flag to
- // be set. Simply set it to the name of the command so that it's
- // unique.
- //
- string $nameCommandCmd = "nameCommand -ann \"" + $nameCommandName
- + "\" -command (\"" + $runTimeCommand + "\") "
- + $nameCommandName;
- eval ($nameCommandCmd);
- $nameCommandIndex = getNameCommand($nameCommandName);
- }
-
- // Are we trying to attach the hotkey to a user Marking Menu?
- //
- // We can determine this by querying the Category flag of the
- // runTimeCommand. All runTimeCommands that post custom
- // Marking Menus will have the category set to
- // "User Marking Menus".
- //
- if ("User Marking Menus"
- == `runTimeCommand -query -category $runTimeCommand`) {
-
- //
- // Why do we need to know if the runTimeCommand is for
- // showing a user marking menu? Because we must
- // ensure that the command that actually shows the
- // marking menu includes the hotkey modifiers.
- //
- // The problem is that the user creates their marking
- // menu in the Marking Menu Editor. At that time we
- // have no idea what hotkey and modifiers the user is
- // going to attach.
- //
- // But now we know their hotkey assignment and simply
- // need to update the command accordingly.
- //
- string $modifiers, $command, $newCommand;
- string $buffer[], $tokens[];
- int $index, $tokenCount;
-
- $command = `runTimeCommand -query -command $runTimeCommand`;
-
- // Determine if the command is for popping up the marking
- // menu or for popping it down.
- //
- // We don't have to modify the pop down command, only
- // the popup command.
- //
- // The pop up command is assumed to consist of three lines
- // separated by new lines, eg "\n".
- //
- $tokenCount = `tokenize $command "\n" $buffer`;
- if (3 == $tokenCount) {
- //
- // This is the marking menu pop up command.
- //
-
- // Start constructing the new command that will include
- // the appropriate hotkey modifiers.
- //
- // Add the first line of the command.
- //
- $newCommand = $buffer[0] + "\n";
-
- // Tokenize the second line so we can find the
- // -ctl, -alt, and -cmd flags and set their correct
- // values.
- //
- $tokenCount = `tokenize $buffer[1] " " $tokens`;
-
- int $altFound = false, $cmdFound = false;
-
- for ($index = 0; $index < $tokenCount; $index++) {
-
- if ("-ctl" == $tokens[$index]) {
- $newCommand += $tokens[$index] + " ";
- if ($ctrl) {
- $newCommand += "true ";
- } else {
- $newCommand += "false ";
- }
- $index++;
-
- } else if ("-alt" == $tokens[$index]) {
- $newCommand += $tokens[$index] + " ";
- if ($alt) {
- $newCommand += "true ";
- } else {
- $newCommand += "false ";
- }
- $altFound = true;
- $index++;
-
- }else if ("-cmd" == $tokens[$index]) {
- $newCommand += $tokens[$index] + " ";
- if ($cmd) {
- $newCommand += "true ";
- } else {
- $newCommand += "false ";
- }
- $cmdFound = true;
- $index++;
-
- } else if ("-allowOptionBoxes" == $tokens[$index]) {
- //
- // The Marking Menu editor didn't use to set the
- // -alt flag. If we've detected the
- // -allowOptionBoxes flag and the -alt flag
- // hasn't been found then insert it as well as
- // its value.
- //
- // Then include the -allowOptionBoxes flag.
- //
- if (!$altFound && !$cmdFound) {
- $newCommand += "-alt ";
- if ($alt) {
- $newCommand += "true ";
- } else {
- $newCommand += "false ";
- }
- }
- $newCommand += $tokens[$index] + " ";
-
- } else {
- //
- // Include all the other parts of the command.
- //
- $newCommand += $tokens[$index] + " ";
- }
- }
-
- // Don't forget to add the last line of the original
- // command.
- //
- $newCommand += "\n" + $buffer[2] + "\n";
-
- // Attach the new command to the runTimeCommand.
- //
- runTimeCommand -edit -command $newCommand $runTimeCommand;
-
- // Update the command info area to reflect the change in
- // the runTimeCommand's command.
- //
- updateCommandInfo();
- }
-
- if ($press) {
- //
- // It would be nice to automatically attach the release
- // hotkey for the user's marking menu.
- //
- string $message = "Your marking menu will not work correctly " +
- "unless you also attach the release hotkey.\nDo you want this " +
- "to be set up for you?";
- $confirmResponse = `confirmDialog -button "Yes" -button "No"
- -defaultButton "Yes" -cancelButton "No"
- -message $message`;
-
- if ("Yes" == $confirmResponse) $setUpReleaseHotkey = true;
- }
- }
-
- string $hotkeyCmd = constructHotkeyCommand(
- $key, $ctrl, $alt, $cmd, $press, $repeat, $nameCommandName);
- eval ($hotkeyCmd);
-
- updateCurrentHotkeys();
- updateQueryHotkeyText();
-
- // Now reset the "Assign Hotkey" field and checkboxes.
- //
- // Fixes bug #126569.
- //
- textField -edit -text "" HotkeyEditorKeyField;
- checkBox -edit -value false HotkeyEditorCtrlCheckBox;
- checkBox -edit -value false HotkeyEditorAltCheckBox;
- if(`about -macOS`){
- checkBox -edit -value false HotkeyEditorCmdCheckBox;
- }
- radioButton -edit -select HotkeyEditorPressRadioButton;
- }
-
- if ($setUpReleaseHotkey) {
- //
- // The user has requested that we also attach the release hotkey
- // for the marking menu.
- //
- // Construct the name of the release runTimeCommand. To do this,
- // take the press runTimeCommand, strip off "_Press" and add
- // "_Release". These are the suffixes added
- // in hotkeyEditor_createMarkingMenu().
- //
- string $releaseName = substring($runTimeCommand, 1, (size($runTimeCommand) - 6));
- $runTimeCommand = $releaseName + "_Release";
- $nameCommandName = $runTimeCommand + "NameCommand";
- $nameCommandIndex = getNameCommand($nameCommandName);
-
- if (0 == $nameCommandIndex) {
- //
- // Create a new nameCommand object.
- //
- // Note that nameCommand command requires the annotation flag to
- // be set. Simply set it to the name of the command so that it's
- // unique.
- //
- string $nameCommandCmd = "nameCommand -ann \"" + $nameCommandName
- + "\" -command (\"" + $runTimeCommand + "\") "
- + $nameCommandName;
- eval ($nameCommandCmd);
- $nameCommandIndex = getNameCommand($nameCommandName);
- }
-
- string $hotkeyCmd = constructHotkeyCommand(
- $key, $ctrl, $alt, $cmd, false, $repeat, $nameCommandName);
- eval ($hotkeyCmd);
- }
- }
-
- global proc hotkeyEditorQueryHotkey()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Query hotkey button.
- //
- {
- if (!updateQueryHotkeyText()) {
- text -edit
- -label "You must enter a valid key\nin the Key field above."
- HotkeyEditorQueryResultText;
- }
- }
-
- global proc hotkeyEditorFindHotkey()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Find hotkey button.
- //
- // The purpose of this procedure is to locate and select
- // in the category/command scroll lists the command assigned
- // to the current hotkey.
- //
- {
- int $cmd = 0;
- string $key = `textField -query -text HotkeyEditorKeyField`;
- int $ctrl = `checkBox -query -value HotkeyEditorCtrlCheckBox`;
- int $alt = `checkBox -query -value HotkeyEditorAltCheckBox`;
- int $press = `radioButton -query -select HotkeyEditorPressRadioButton`;
-
- if(`about -macOS`){
- $cmd = `checkBox -query -value HotkeyEditorCmdCheckBox`;
- }
- if ("" == $key || !isValidKey($key)) {
- //
- // Won't be able to find command attached to invalid key.
- //
- text -edit
- -label "You must enter a valid key\nin the Key field above."
- HotkeyEditorQueryResultText;
-
- } else {
- string $command = getHotkeyCommand($key, $ctrl, $alt, $cmd, $press);
-
- if ("" == $command) {
- //
- // No command assigned.
- //
- string $label = "\"";
- if ($ctrl) {
- if(`about -macOS`)
- $label += ("control+");
- else
- $label += ("Ctrl+");
-
- }
- if ($alt) {
- if(`about -macOS`)
- $label += ("option+");
- else
- $label += ("Alt+");
- }
- if($cmd){
- if(`about -macOS`)
- $label += ("command+");
- else
- $label += ("Command+");
- }
- $label += $key;
-
- if (!$press) {
- $label += " Release";
- }
- $label += "\" is assigned to:\n Nothing";
-
- text -edit -label $label HotkeyEditorQueryResultText;
-
- } else {
- //
- // Select the corresponding category and command in the
- // scroll lists.
- //
- string $category = `runTimeCommand -query -category $command`;
- textScrollList -edit -selectItem $category
- HotkeyEditorCategoryTextScrollList;
- updateCommandTextScrollList($command);
- }
- }
- }
-
- global proc hotkeyEditorRemoveHotkey()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Remove hotkey button.
- //
- {
- // Get the selected hotkey item in the scroll list.
- //
- string $hotkey[] = `textScrollList -query
- -selectItem HotkeyEditorHotkeyTextScrollList`;
-
- removeHotkey($hotkey[0]);
-
- updateCurrentHotkeys();
- }
-
- global proc hotkeyEditorRestoreDefaultHotkeys()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Restore Defaults button.
- //
- // Post a dialog confirming the user wants to restore the
- // default hotkeys and thus losing all their custom hotkey
- // assignments.
- //
- // Then restore the default hotkeys.
- //
- {
- string $message, $response;
-
- $message = "All user defined hotkey assignments will be irretrievably " +
- "lost.\nContinue restoring default hotkey assignments?";
-
- $response = `confirmDialog -button "Yes" -button "Cancel"
- -defaultButton "Yes" -cancelButton "Cancel" -message $message`;
-
- if ($response == "Yes") {
- hotkey -factorySettings;
- updateCurrentHotkeys();
- }
- }
-
- global proc hotkeyEditorListAllHotkeys()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // List All hotkeys button.
- //
- {
- listHotkeysWindow;
- }
-
- global proc hotkeyEditorSave()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Save button.
- //
- {
- savePrefs -hotkeys;
- }
-
- global proc hotkeyEditorClose()
- //
- // Description:
- // This procedure is called whenever the user presses the
- // Close button.
- //
- {
- deleteUI -window HotkeyEditor;
- }
-
- // ------------------------------------------------------------------
- //
- // BEGIN: interface to the Marking Menu Editor, and related routines.
- //
- // These procedures should only be called by the Marking Menu Editor.
- //
- proc string hotkeyEditor_generatePressAnnotationForMM(string $annotation)
- {
- return ($annotation + " (Press)");
- }
-
- proc string hotkeyEditor_generateReleaseAnnotationForMM(string $annotation)
- {
- return ($annotation + " (Release)");
- }
-
- global proc int hotkeyEditor_createMarkingMenu(
- string $markingMenuName,
- string $pressCommandString,
- string $releaseCommandString)
- //
- // Description:
- // Create the runTimeCommands for a marking menu.
- //
- // Returns false upon failure.
- //
- {
- // Has a marking menu with the given marking menu name already
- // been created?
- //
- if (hotkeyEditor_doesMarkingMenuExist($markingMenuName)) {
- warning "A Marking Menu with this name already exists in the Hotkey Editor";
- return false;
- }
-
- // Create a couple of runTimeCommands. One for the press command and
- // one for the release command.
- //
- // Is the given marking menu name valid? Ie. no spaces, punctuation, etc.?
- //
- string $popUpCommandName = $markingMenuName + "_Press";
- string $popDownCommandName = $markingMenuName + "_Release";
-
- string $pressAnnotation = hotkeyEditor_generatePressAnnotationForMM($markingMenuName);
- string $releaseAnnotation = hotkeyEditor_generateReleaseAnnotationForMM($markingMenuName);
-
- string $runTimeCommand;
-
- $runTimeCommand = ("runTimeCommand " + $popUpCommandName);
- eval ($runTimeCommand);
-
- runTimeCommand -edit
- -command $pressCommandString
- -category "User Marking Menus"
- -annotation $pressAnnotation
- $popUpCommandName;
-
- $runTimeCommand = ("runTimeCommand " + $popDownCommandName);
- eval ($runTimeCommand);
-
- runTimeCommand -edit
- -command $releaseCommandString
- -category "User Marking Menus"
- -annotation $releaseAnnotation
- $popDownCommandName;
-
- if (`window -exists HotkeyEditor`) {
- //
- // If the Hotkey Editor is currently visible then update
- // the window to reflect the presence of a new command.
- //
- if (!isExistingCategory("User Marking Menus")) {
- //
- // Update the category popup menu so it includes the new
- // category.
- //
- updateCategoryPopupMenu();
-
- // Add the new category to the list of categories.
- //
- textScrollList -edit -append "User Marking Menus"
- HotkeyEditorCommandTextScrollList;
- }
-
- // Update the command list if necessary.
- //
- if ("User Marking Menus" == getCurrentCategory()) {
- updateCommandTextScrollList($popUpCommandName);
- }
- }
- return true;
- }
-
- global proc hotkeyEditor_deleteMarkingMenu(string $markingMenuName)
- //
- // Description:
- // Delete the runTimeCommands for a marking menu.
- //
- {
- string $popUpCommandName = $markingMenuName + "_Press";
- string $popDownCommandName = $markingMenuName + "_Release";
-
- deleteRunTimeCommand($popUpCommandName);
- deleteRunTimeCommand($popDownCommandName);
-
- if (`window -exists HotkeyEditor`) {
- //
- // If the Hotkey Editor is currently visible then update
- // the window to reflect the removal of the commands.
- //
-
- // Update the command list if necessary.
- //
- if ("User Marking Menus" == getCurrentCategory()) {
- updateCommandTextScrollList("");
- }
- }
- }
-
- global proc int hotkeyEditor_renameMarkingMenu(
- string $oldMarkingMenuName,
- string $newMarkingMenuName,
- string $newPressCommandString,
- string $newReleaseCommandString)
- //
- // Description:
- // Rename the runTimeCommands associated with a marking menu.
- //
- {
- int $result = false;
-
- // Not much to do if the name marking menu name hasn't changed.
- //
- if ($oldMarkingMenuName == $newMarkingMenuName) return true;
-
- // Simply create new runTimeCommands based on the new name.
- //
- $result = hotkeyEditor_createMarkingMenu(
- $newMarkingMenuName,
- $newPressCommandString,
- $newReleaseCommandString);
-
- // If successful in creating the new commands then delete the old
- // commands.
- //
- if ($result) {
- string $oldPopUpCommandName = $oldMarkingMenuName + "_Press";
- string $oldPopDownCommandName = $oldMarkingMenuName + "_Release";
-
- deleteRunTimeCommand($oldPopUpCommandName);
- deleteRunTimeCommand($oldPopDownCommandName);
-
- if (`window -exists HotkeyEditor`) {
- //
- // If the Hotkey Editor is currently visible then update
- // the window to reflect the removal of the commands.
- //
-
- // Update the command list if necessary.
- //
- if ("User Marking Menus" == getCurrentCategory()) {
- updateCommandTextScrollList("");
- }
- }
- }
- return $result;
- }
-
- global proc int hotkeyEditor_doesMarkingMenuExist(string $markingMenuName)
- //
- // Description:
- // Return true if a marking menu with the given name already
- // exists.
- //
- {
- int $result = true;
-
- string $popUpCommandName = $markingMenuName + "_Press";
- string $popDownCommandName = $markingMenuName + "_Release";
-
- if (!`runTimeCommand -exists $popUpCommandName` &&
- !`runTimeCommand -exists $popDownCommandName`) {
- $result = false;
- }
-
- return $result;
- }
- //
- // END: interface to the Marking Menu Editor, and related routines
- //
- // ---------------------------------------------------------------
-
- global proc hotkeyEditor()
- //
- // Description:
- // Create the Hotkey Editor.
- //
- {
- // If the window already exists then just show it and return.
- //
- if (`window -exists HotkeyEditor`) {
- showWindow HotkeyEditor;
- return;
- }
-
- // Otherwise, build the window.
- //
- window -title "Hotkey Editor" -height 700 -width 700 HotkeyEditor;
-
- string $form = `formLayout`;
-
- string $commandListArea = `formLayout`;
- setParent ..;
- string $commandInfoArea = `formLayout`;
- setParent ..;
- string $hotkeyArea = `formLayout`;
- setParent ..;
- string $buttonsArea = `formLayout`;
- setParent ..;
-
- setParent $hotkeyArea;
- string $currentHotkeyArea = `formLayout`;
- setParent ..;
- string $newHotkeyArea = `formLayout`;
- setParent ..;
-
- createCommandListArea($commandListArea);
- createCommandInfoArea($commandInfoArea);
- createCurrentHotkeyArea($currentHotkeyArea);
- createNewHotkeyArea($newHotkeyArea);
- createButtonsArea($buttonsArea);
-
- formLayout -edit
- -attachForm $currentHotkeyArea "top" 0
- -attachForm $currentHotkeyArea "left" 0
- -attachNone $currentHotkeyArea "bottom"
- -attachForm $currentHotkeyArea "right" 0
- -attachControl $newHotkeyArea "top" 20 $currentHotkeyArea
- -attachForm $newHotkeyArea "left" 0
- -attachNone $newHotkeyArea "bottom"
- -attachForm $newHotkeyArea "right" 0
- $hotkeyArea;
-
- formLayout -edit
- -attachForm $commandListArea "top" 5
- -attachForm $commandListArea "left" 5
- -attachControl $commandListArea "bottom" 15 $commandInfoArea
- -attachControl $commandListArea "right" 5 $hotkeyArea
- -attachForm $hotkeyArea "top" 5
- -attachNone $hotkeyArea "left"
- -attachControl $hotkeyArea "bottom" 15 $commandInfoArea
- -attachForm $hotkeyArea "right" 5
- -attachNone $commandInfoArea "top"
- -attachForm $commandInfoArea "left" 5
- -attachControl $commandInfoArea "bottom" 5 $buttonsArea
- -attachForm $commandInfoArea "right" 5
- -attachNone $buttonsArea "top"
- -attachForm $buttonsArea "left" 5
- -attachForm $buttonsArea "bottom" 5
- -attachForm $buttonsArea "right" 5
- $form;
-
- resetCreateOrEditMode();
- updateCommandTextScrollList("");
- updateCategoryPopupMenu();
- updateKeyPopupMenu();
-
- showWindow HotkeyEditor;
- }
-